﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Globalization;
using System.Web.Security;
using WebMatrix.WebData;
using System.Web;

namespace G28BS.Models
{


    public enum UserStates
    {
        // Active= Normal user, Disabled=User have been banned, Deleted=User deleted.
        Active = 0,
        Disabled = 1,
    }

    [Table("UserProfile")]
    public class UserProfile
    {

        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        [Display(Name = "Númer notanda (ID)")]
        public int UserId { get; set; }
        //public Rank userRank { get; set; }
        [Required]
        [Display(Name = "Notandanafn")]
        public string UserName { get; set; }
        
        [Display(Name = "Mynd")]
        public string userImage { get; set; }
        [Display(Name = "Upplýsingar")]
        public string userDescription { get; set; }
        [Display(Name = "Netfang")]
        public string userEmail { get; set; }
        [Display(Name = "Aldur")]
        public int? age { get; set; }
        [Display(Name = "Kyn")]
        public string gender { get; set; }

        [Display(Name = "Fjöldi spilaðra leikja")]
        public int gameCount { get; set; }
        // game defaults; failure to act; inaction or neglect.
        [Display(Name = "Fjöldi leikja sem hætt í")]
        public int gameDefaultCount { get; set; }
        [Display(Name = "Fjöldi neikvæðra dóma")]
        public int negativeReviewCount { get; set; }
        [Display(Name = "Staða")]
        public UserStates userState { get; set; }

        // Unable to get Data.Annotations to work, I turn to Fluent API




        // Return copies of this object for secure use,
        // not revieling sensitive user information such as email.
        public UserProfile SafeInformationCopy()
        {
            return new UserProfile
            {
                UserId = UserId,
                UserName = UserName,
                userDescription = userDescription,
                userEmail = "",
                age = -1,
                gender = "",
                userImage = userImage,
                gameCount = gameCount,
                gameDefaultCount = gameDefaultCount,
                negativeReviewCount = negativeReviewCount,
                userState = userState
            };
        }
    }



    public class RegisterExternalLoginModel
    {
        [Required]
        [Display(Name = "Notandanafn")]
        public string UserName { get; set; }

        public string ExternalLoginData { get; set; }
    }

    public class LocalPasswordModel
    {
        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Núverandi aðgangsorð")]
        public string OldPassword { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "{0} þarf að vera að minnsta kosti {2} stafir að lengd.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "Nýtt aðgangsorð")]
        public string NewPassword { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "Staðfesta nýtt aðgangsorð")]
        [Compare("NewPassword", ErrorMessage = "Nýja aðgangsorðið og staðfesting þess eru ekki eins.")]
        public string ConfirmPassword { get; set; }
    }

    public class LoginModel
    {
        [Required]
        [Display(Name = "Notandanafn")]
        public string UserName { get; set; }

        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Aðgangsorð")]
        public string Password { get; set; }

        [Display(Name = "Muna mig?")]
        public bool RememberMe { get; set; }
    }

    public class RegisterModel
    {
        [Required]
        [StringLength(100, ErrorMessage = "{0} þarf að vera að minnsta kosti {2} stafir að lengd.", MinimumLength = 3)]
        [DataType(DataType.Text)]
        [Display(Name = "Notandanafn")]
        public string UserName { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "{0} þarf að vera að minnsta kosti {2} stafir að lengd.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "Aðgangsorð")]
        public string Password { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "Staðfesta aðgangsorð")]
        [Compare("Password", ErrorMessage = "Aðgangsorðið og staðfesting þess eru ekki eins.")]
        public string ConfirmPassword { get; set; }
    }

    public class ExternalLogin
    {
        public string Provider { get; set; }
        public string ProviderDisplayName { get; set; }
        public string ProviderUserId { get; set; }
    }
}
